﻿var t = null;
var msgBox = null;
$(function () {
    msgBox = new MsgBox({ imghref: "../images/" });
    $('select[class=_SelectChanged]').bind('change', function () {
        var tt = $($(this).children('option:selected')); 
        var typeid = tt.attr("typeid");
        var userId = tt.attr("userId");
        var _value = tt.val();
        $.post("../Action/UsersManager.ashx", { type: "change", typeid: typeid, userId: userId, value: _value }, function (jsObj) {
            if (jsObj.statu == "ok")
            {
                msgBox.showMsgOk(jsObj.msg);
            }
        }, "json");
    });
});
function doDel(userid, btn)
{
    debugger;
    t = $(btn);
    var strcarMsg = "";
    var strorderMsg = "";
    var tr = $(btn).parent().parent();
    var tdcar = $(tr).find('td').get(1);
    if ($(tdcar).text() == "是") {
        var tdscar = true;
        strcarMsg = "用户有过购物记录";
    } else {
        var tdscar = false;
    }
    var tdorder = $(tr).find('td').get(2);
    if ($(tdorder).text() == "是") {
        var tdsorder = true;
        strorderMsg = "和订单记录";
    } else {
        var tdsorder = false;
    }
    if (window.confirm("确定要删除【" + $($(tr).find('td').get(0)).text() + "】? " + strcarMsg + "" + strorderMsg + "")) {
        $.post("../Action/UsersManager.ashx", { type: "usermanager",userId:userid, tdsorder: tdsorder, tdscar: tdscar}, function (jsObj) {
            debugger;
            processData(jsObj);
            if (jsObj.data == "true")
            {
                $(t.parent().parent()).remove();
            }
        }, "json");
    } else {
        return;
    }
}
function processData(jsObj, okFunc, errFunc) {
    //根据返回的 数据 状态 执行相应的操作
    switch (jsObj.statu) {
        case "ok"://如果ok则执行 ok回调函数
            if (okFunc) okFunc();
            msgBox.showMsgOk(jsObj.msg);
            break;
        case "err"://如果err的话，则 执行 err 回调函数
            if (errFunc) errFunc();
            msgBox.showMsgErr(jsObj.msg);
            break;
        case "np"://没有权限，则直接跳转到指定页面
            msgBox.showMsgErr(jsObj.msg, function () {
                window.location = jsObj.nextUrl;
            });
            break;
    }
}